<script setup lang='ts'>
import { PureTableBar } from "@/components/RePureTableBar";
import { useFincilaLending } from "./hooks/FincilaLending";
const {
  columns,
  loading,
  dataList,
  pagination,
  handleSizeChange,
  handleCurrentChange,
  DialogVisible,
  rowData,
  handleApply,
  handelSupplierPay,
  payLeaveMoney,
  payData,
  handlePayData,
  selectRouteTypeVisible,
  routerTittle,
  saveApply,
  payBalanceVisible,
  handleLender,
  lenderVisible
} = useFincilaLending()
</script>
    <!-- 入住电商平台 -->
<template>
  <div class="main">
    <PureTableBar title="融资放款列表" class="list_hei">
      <template v-slot="{ size, checkList }">
        <pure-table border align-whole="center" showOverflowTooltip table-layout="auto" adaptive :loading="loading"
          size="small" :data="dataList" max-height="600" :columns="columns" :checkList="checkList"
          :pagination="pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)'
          }">
          <template #operation="{ row }">
            <div v-if="row.paymentStatus == 0">
              <el-button type='primary' text @click="handleApply(row, 1)">
                自有资金放款
              </el-button>
              <el-button type='primary' text @click="handleApply(row, 2)">
                发起资产证券化项目
              </el-button>
            </div>
            <div v-if="row.routeType == 1">
              <div v-if="row.paymentStatus == 2">
                <el-button type='primary' size="small" text>
                  已放款
                </el-button>
              </div>
              <div v-if="row.paymentStatus == 4">
                <el-button type='primary' size="small" text @click="handlePayData(row)">
                  支付余额
                </el-button>
              </div>
              <div v-if="row.paymentStatus == 5">
                <el-button type='primary' size="small" text>
                  已支付
                </el-button>
              </div>
            </div>
            <div v-if="row.routeType == 2">
              <div v-if="row.paymentStatus == 1">
                <el-button type='primary' size="small" text>
                  待放款
                </el-button>
              </div>
              <div v-if="row.paymentStatus == 2">
                <el-button type='primary' size="small" text @click="handleLender(row)">
                  点击放款
                </el-button>
              </div>
              <div v-if="row.paymentStatus == 3">
                <el-button type='primary' size="small" text>
                  已放款
                </el-button>
              </div>
              <div v-if="row.paymentStatus == 4">
                <el-button type='primary' size="small" text @click="handlePayData(row)">
                  支付余额
                </el-button>
              </div>
              <div v-if="row.paymentStatus == 5">
                <el-button type='primary' size="small" text>
                  已支付
                </el-button>
              </div>
            </div>
          </template>
        </pure-table>
      </template>
    </PureTableBar>
  </div>


  <ReDialog :width="500" :height="150" :models="selectRouteTypeVisible" @Closes="selectRouteTypeVisible = false">
    <template #header>
      <h2 style=" text-align: center;">操作</h2>
    </template>
    <template #main>
      <!-- 选择资产证券化或者自有资金弹窗 -->
      <span class="h-full flex justify-center  f-14 flex-direction-column"> {{ routerTittle }}</span>
    </template>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="saveApply()">确定</el-button>
        <el-button @click="selectRouteTypeVisible = false"> 取消 </el-button>
      </span>
    </template>
  </ReDialog>

  <ReDialog :width="500" :height="150" :models="payBalanceVisible" @Closes="payBalanceVisible = false">
    <template #header>
      <h2 style=" text-align: center;">操作</h2>
    </template>
    <template #main>
      <!-- 支付余额弹窗 -->
      <span class="h-full flex justify-center  f-14 flex-direction-column"> {{ routerTittle }}</span>
    </template>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="payLeaveMoney()">确定</el-button>
        <el-button @click="payBalanceVisible = false"> 取消 </el-button>
      </span>
    </template>
  </ReDialog>

  <ReDialog :width="500" :height="150" :models="lenderVisible" @Closes="lenderVisible = false">
    <template #header>
      <h2 style=" text-align: center;">操作</h2>
    </template>
    <template #main>
      <!-- 融资放款弹窗 -->
      <span class="h-full flex justify-center  f-14 flex-direction-column"> {{ routerTittle }}</span>
    </template>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="handelSupplierPay()">确定</el-button>
        <el-button @click="lenderVisible = false"> 取消 </el-button>
      </span>
    </template>
  </ReDialog>
</template>

<style scoped lang="scss">
@import url(@/style/CreditComm.scss);

:deep(.el-dialog__footer) {
  text-align: center;
}
</style>
